/**
 * 
 */
package ar.com.jsejtman.cajugastos2.view.util;

import java.io.IOException;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import org.codehaus.jackson.JsonGenerator;
import org.codehaus.jackson.map.JsonSerializer;
import org.codehaus.jackson.map.SerializerProvider;
import org.springframework.stereotype.Component;

/**
 * Used to serialize {@link BigDecimal}, which is not a common JSON type, so we have to create a custom
 * serialize method;.
 * 
 * @author Julio Sejtman
 */
@Component
public class JsonPlataSerializer extends JsonSerializer<BigDecimal> {

	/**
	 * Formateador de Plata.
	 */
	private static final NumberFormat NUMBER_FORMAT = new DecimalFormat("$ #.00");

	@Override
	public void serialize(final BigDecimal monto, final JsonGenerator gen,
	        final SerializerProvider provider) throws IOException {

		final String formattedDate = JsonPlataSerializer.NUMBER_FORMAT.format(monto);

		gen.writeString(formattedDate);
	}

}
